package com.studio.bill.swiperecyclerdemo.util.libimage;

import android.content.Context;
import android.widget.ImageView;

import com.studio.bill.swiperecyclerdemo.MainApplication;

/**
 * @author: tangjie
 * @date: 2017/3/22 11:16
 * @Description:
 */

public class ImageLoader {

    private static ImageLoader mInstance = new ImageLoader(MainApplication.getInstance());
    private BaseImageLoaderStrategy mStrategy;

    private ImageLoader(Context context) {
        if (null == context) {
            return;
        }
        mStrategy = new GlideStrategy(context.getApplicationContext());
    }

    //single instance
    public static ImageLoader getInstance() {
        if (mInstance == null) {
            throw new IllegalArgumentException("ImageLoader not init!");
        }
        return mInstance;
    }

    public static void init(Context context) {
        // do nothing
    }

    public void displayImage(String imageUrl, ImageView imageView) {
        mStrategy.displayImage(imageUrl, imageView);
    }

    public void displayImage(String imageUrl, ImageView imageView, ImageConfig imageConfig) {
        mStrategy.displayImage(imageUrl, imageView, imageConfig);
    }

    public void loadImage(String imageUri, ImageConfig imageConfig, BaseImageLoaderStrategy.Callback callback) {
        mStrategy.loadImage(imageUri, imageConfig, callback);
    }

    public void setLoadImgStrategy(BaseImageLoaderStrategy strategy) {
        mStrategy = strategy;
    }

    public void pauseRequests() {
        mStrategy.pauseRequests();
    }

    public void resumeRequests() {
        mStrategy.resumeRequests();
    }
}
